package test.y2021;

import cn.hutool.core.lang.Console;
import com.alibaba.fastjson.JSON;

import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created By  醉美柳舞之众星捧月
 *
 * @author song
 * @date 2021/11/19 14:06
 */
public class November2 {
    /**
     * Author song  醉美柳舞之众星捧月
     * Date & Time  2021/11/19 14:34
     * Description  缓冲区
     */
    public static void main(String[] args) throws FileNotFoundException {
        List<Object> objects = new ArrayList<>();
        for (int i = 0; i < 100_000; i++) {
            objects.add(new Random().nextInt());
        }
        Console.error(JSON.toJSONString(objects));

        long l = System.currentTimeMillis();
        int bufferSize = 4 * 1024;
        BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream("/test.txt"), bufferSize);
        objects.forEach(i -> {
            try {
                bufferedOutputStream.write(i.toString().getBytes());
            } catch (IOException e) {
                e.printStackTrace();
            }
        });
        long a = System.currentTimeMillis() - l;
        Console.error("--------->>>>>>>>>:" + a);
    }
}
